package com.zzty.zzlp.serviceimpl;

import com.zzty.zzlp.dao.ArticleMapper;
import com.zzty.zzlp.entity.Article;
import com.zzty.zzlp.entity.Twitter;
import com.zzty.zzlp.service.EditService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Service

public class EditServiceImpl implements EditService {

    @Autowired
    ArticleMapper am;

    @Override
    public int insert(Article record) {
        return am.insert1(record);
    }

    public List<Article> selectAllArticle(){
        return am.selectAllArticle();
    }


    public List getImg() {
        List<Article> lista = selectAllArticle();
        List imgList = new ArrayList() ;
        for(int i = 0 ; i < lista.size();i++){
            String imgs = lista.get(i).getImgUrl();
            System.out.println("imgs=============="+imgs);
            if(imgs!=null){
                String [] tmp=imgs.split("\\|");
                imgList = Arrays.asList(tmp);
                lista.get(i).setImgs(imgList);
                tmp = null;
            }

        }
        return lista;
    }

    public List<Article> selectSelf(Integer userId){
        return am.selectSelf(userId);
    }


    public List getSelfImg(Integer userId) {
        List<Article> listas = selectSelf(userId);
        List imgList = new ArrayList() ;
        for(int i = 0 ; i < listas.size();i++){
            String imgs = listas.get(i).getImgUrl();
            System.out.println("imgs=============="+imgs);
            if(imgs!=null){
                String [] tmp=imgs.split("\\|");
                imgList = Arrays.asList(tmp);
                listas.get(i).setImgs(imgList);
                tmp = null;
            }

        }
        return listas;
    }
}
